package com.daiqee.controller;

import com.daiqee.controller.support.CommonsController;
import com.daiqee.enums.RequestType;
import com.daiqee.pojo.ProcurementPlan;
import com.daiqee.pojo.ProcurementProduction;
import com.daiqee.service.impl.ProcurementPlanService;
import com.daiqee.service.impl.ProcurementProductionService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 采购计划
 * 
 * <br/>
 * @since JDK 1.8
 * @version  V2.1
 * @author RichardTang 
 * @date: 2018年5月7日 下午5:54:40
 * @package com.daiqee.handler
 * @copyright:Copyright (c) 2018, 1245811923@qq.com All Rights Reserved.
 */
@Controller
@RequestMapping("procurement/procurement-plan")
public class ProcurementPlanController extends CommonsController<ProcurementPlan>{
	
	@Autowired
	private ProcurementPlanService procurementPlanService; 
	
	@Autowired
	private ProcurementProductionService procurementProductionService;
	
	@RequestMapping(method = RequestMethod.POST,params = "method")
	public Object addPlan(@RequestBody ProcurementPlan procurementPlan){
		isNormalFinish = procurementPlanService.addProcurementPlan(procurementPlan) > 0;
		return restfulResponse.response(isNormalFinish, RequestType.POST);
	}
	
	/**
	 * 根据id来查询对应的产品
	 * @param procureId
	 * 			采购单id号
	 * @return 查询到的产品实体
	 */
	@RequestMapping(value="/{procureId}",method=RequestMethod.GET)
	public Object queryById(@PathVariable("procureId") Integer procureId) {
		ProcurementProduction procureProduct = 
		    procurementProductionService.selectById(procureId);
		return restfulResponse.response(procureProduct,RequestType.GET);
	}
	
	@RequestMapping(method = RequestMethod.PUT,params = "method")
	public Object update(@RequestBody ProcurementPlan procurementPlan) {
		isNormalFinish = procurementPlanService.updateProcurementPlan(procurementPlan) > 0;
		return restfulResponse.response(isNormalFinish,RequestType.PUT);
	}
	
	@Override
	public boolean warpperDeleteMethod(String ids, List<String> idList) {
		return procurementPlanService.removeProcurementPlans(idList) > 0;
	}
}
